<?php

namespace App\Providers;

use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;

class RouteServiceProvider extends ServiceProvider
{
    public const HOME = '/';
    
    protected $namespace = 'App\\Http\\Controllers';
    
    public function boot()
    {
        $this->configureRateLimiting();

        $this->routes(function () {
         
        	Route::prefix('api')
                ->middleware('api')
                ->namespace('App\\Http\\Controllers\\Api')
	            ->name('api.')
                ->group(base_path('routes/api.php'));
	
	        // api.v1.
	        Route::prefix('api/v1')
		        ->middleware('api')
		        ->namespace('App\\Http\\Controllers\\Api\\V1')
		        ->name('api.v1.')
		        ->group(base_path('routes/api_v1.php'));

	        // wap
            Route::prefix('wap')
	            ->middleware('web')
                ->namespace('App\\Http\\Controllers\\Wap')
	            ->name('wap.')
                ->group(base_path('routes/wap.php'));

	        // web
            Route::middleware('web')
                ->namespace($this->namespace)
	            ->name('web.')
                ->group(base_path('routes/web.php'));
        });
    }
    
    protected function configureRateLimiting()
    {
        RateLimiter::for('api', function (Request $request) {
            return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
        });
    }
}
